#include <stdio.h>
#include <stdlib.h>



// #include <complex.h>
// #include <fftw3.h>

void print(double *data,int size)
{
    for(int i = 0;i < size;++i){
        printf("%f ",data[i]);
    }
    printf("\n");
}

void extract_subband(double *data,double *subband,long size,int nfft,int index)
{
    for(int i = 0,j = 0;i < size;){
        subband[j] = data[i+index];
        j += 1;
        i += nfft;
    }
}
/**
 * 
#include <fftw3.h>
#include <complex.h>
 */
// void shift_freq(fftw_complex *freq,long size)
// {
//     double real,imag;
//     for(int i = 0;i < size / 2;++i){
//         real = freq[i][0];
//         imag = freq[i][1];
//         freq[i][0] = freq[i+size/2][0];
//         freq[i][1] = freq[i+size/2][1];
//         freq[i+size/2][0] = real;
//         freq[i+size/2][1] = imag;
//     }
// }

/**
#include <complex.h>
#include <fftw3.h>
 */
// void shift_freq1(fftw_complex *freq,long size)
// {
//     fftw_complex temp;
//     for(int i = 0;i < size / 2;++i){
//         temp = freq[i];
//         freq[i] = freq[i+size/2];
//         freq[i+size/2] = temp;
//     }
// }

int main()
{
    double *a = malloc(sizeof(double) * 20);
    double *b = malloc(sizeof(double) * 20);

    int nfft = 5;

    int size = 20 / nfft;

    // fftw_complex *freq = malloc(sizeof(fftw_complex) * 20);

    // for(int i = 0;i < 20;++i){
    //     freq[i] = i+1 + (i+1) * I;
    // }

    for(int i = 0;i < 20;++i){
        a[i] =  i;
    }

    // shift_freq1(freq,20);

    for(int i = 0;i < nfft;++i){
        extract_subband(a,b+i*size,20,nfft,i);
    }

    

    // for(int i = 0;i < 20;++i){
    //     printf("%f,%f\n",creal(freq[i]),cimag(freq[i]));
    // }
    print(b,20);
    return 0;

}